$(function () {
    $("#page").load("/back/page.html");
    // findAll();
});

function xinzeng() {
    $("#right").load("/back/room/roomAdd.html");
}

function findAll() {
    let data = {};
    data.roomId = $("#roomId").val();
    data.roomType = $("#roomStyle option:selected").text();
    data.startRoomPrice = $("#startRoomPrice").val();
    data.endRoomPrice = $("#endRoomPrice").val();
    data.roomTitle = $("#roomTitle").val();
    data.pageSize = $.trim($("#pageSize").val());
    data.pageNum = $.trim($("#pageNum").val());
    data.token = $.cookie("token");
    let result = myAjax('/back/room/roomFindAll', 'get', data);
    showRoom(result.list);
    $("#pageCount").html(result.number);
}

function showRoom(data) {
    let html = "";//进行字符串拼接
    for (let i = 0; i < data.length; i++) {
        html += ' <tr>\n' +
            '      <td>' + data[i].roomId + '</td>\n"' +
            '       <td>' + data[i].roomType + '</td>\n' +
            '        <td>' + data[i].roomPrice + '</td>\n' +
            '        <td>' + data[i].roomTitle + '</td>\n' +
            '        <td><img src="' + data[i].roomPhoto + '"> </td>\n' +
            '        <td>' + data[i].roomIntroduce + '</td>\n' +
            '        <td><a  href="javascript:edit( ' + data[i].roomId + ')">编辑</a> <a  href="javascript:del( ' + data[i].roomId + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#roomFindAll").html(html)//对当前的tbody进行赋值
}

function edit(roomId) {
    localStorage.setItem("roomId", roomId);
    //sessionStorage.setItem("userId",id);   本地存储  两种方式都可以
    $('#right').load('/back/room/roomEdit.html');//页面跳转
}

function del(roomId) {
    let result = myAjax('/back/room/delete', 'get', {roomId: roomId, token: $.cookie("token")});
    if (result.count === 1) {
        $("#right").load('/back/room/roomList.html');
    } else {
        alert("删除失败")
    }
}
